//
//  HKSessionTask.swift
//  
//
//  Created by xp on 2023/4/3.
//

import Foundation

public class HKSessionTask {
    
    public private(set) var task: URLSessionTask
    public private(set) var receivedData: Data
    
    public var callBack: VoidBlock?
    public var completionBlock: VoidBlock?
    
    deinit {
        print(" ====== HKSessionTask deinit ====== ")
    }
    
    public init(task: URLSessionTask) {
        self.task = task
        receivedData = .init()
    }
    
    func addData(_ data: Data) {
        receivedData.append(data)
    }
    
    
}

public extension HKSessionTask {
    
    func resume() {
        task.resume()
    }
    
}

public extension URLSessionTask {
    func convert() -> HKSessionTask {
        .init(task: self)
    }
}
